package cn.b.sky.mes.mm.service.impl;

import java.util.List;

import javax.annotation.Resource;

import cn.b.sky.mes.mm.model.Distributionmode;
import cn.b.sky.mes.mm.service.DistributionmodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import cn.b.sky.mes.mm.model.condition.DistributionmodeCondition;
import cn.b.sky.common.utils.DatabaseUtils;
import org.apache.commons.lang3.StringUtils;

@Service("DistributionmodeService")
public class DistributionmodeServiceImpl implements DistributionmodeService {

	private static final Logger LOGGER = LoggerFactory.getLogger(DistributionmodeServiceImpl.class);
	  @Resource
      cn.b.sky.mes.mm.dao.DistributionmodeDao DistributionmodeDao;
	@Override
	public List<Distributionmode> selectdistributionmodeList(
			DistributionmodeCondition distributionmodeCondition) {
		if (null==distributionmodeCondition){
			return null;
		}
		 if (StringUtils.isEmpty(distributionmodeCondition.getOrderField())) {
		      distributionmodeCondition.setOrderField("CreateDateTime");
		    }
		return DistributionmodeDao.selectdistributionmodeList(distributionmodeCondition);
	}

	@Override
	public int getDistributionmodeCount(
			DistributionmodeCondition distributionmodeCondition) {
		
		return DistributionmodeDao.getDistributionmodeCount(distributionmodeCondition);
	}

	@Override
	public Distributionmode getDistributionmode(String siteCode, String distributionModeCode) {
		
		return DistributionmodeDao.getDistributionmode(siteCode,distributionModeCode);
	}

	@Override
	public void insertDistributionmode(Distributionmode distributionmode) {
		
		DistributionmodeDao.insertDistributionmode(distributionmode);
	}

	@Override
	public void updateDistributionmode(Distributionmode distributionmode) {
		
		DistributionmodeDao.updateDistributionmode(distributionmode);
	}

	@Override
	public int getDistributionModeExactCount(
			DistributionmodeCondition distributionmodeCondition) {
		
		return DistributionmodeDao.getDistributionModeExactCount(distributionmodeCondition);
	}

	@Override
	public String deleteDistributionmode(String siteCode, String code) {
		 String message = null;    
		    try {
		    	DistributionmodeDao.deleteDistributionmode(siteCode, code);
		    } catch (Exception e) {
		    	LOGGER.error("{}", e);
		      if ((DatabaseUtils.isConstraintsError(e.getMessage()))) {
		        message="dataBaseOperationPkFail.M";
		      }
		    }
		    return message;
	}

  @Override
  public List<Distributionmode> selectAlldistributionmode(boolean isContainLock) {
    return DistributionmodeDao.selectAlldistributionmode(isContainLock);
  }
}

